﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        private string username;
        private string power;
        private DateTime logonTime;

        public void setUsername(string username)
        {
            this.username = username;
        }
        public void setPower(string power)
        {
            this.power = power;
        }
        public void setLogonTime(DateTime logonTime)
        {
            this.logonTime = logonTime;
        }
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            if (!RuningData.FormDir.ContainsKey(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name))
            {
                RuningData.FormDir.Add(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name, this);
            }
            toolStripStatusLabel2.Text = username;
            toolStripStatusLabel4.Text = returnPowerName(power.Trim());
            toolStripStatusLabel6.Text = logonTime.ToString();
            listView1.LargeImageList = imageList1;
            RuningData.RoomsInit();
            this.flushRoomImage();
        }
        private string returnPowerName(string power)
        {
            string returnPowerName = null;
            switch (power)
            {
                case "0": { returnPowerName = "数据库管理员"; }; break;
                case "1": { returnPowerName = "大堂经理"; }; break;
                case "2": { returnPowerName = "普通员工"; }; break;
            }
            return returnPowerName;
        }

        private void 数据库管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        public void flushRoomImage()
        {
            listView1.Clear();
            foreach (RoomModel item in RuningData.Rooms)
            {
                string zt = item.RoomZT;
                if (zt.Trim().Equals("待用"))
                {
                    listView1.Items.Add(item.RoomName+"-"+item.ID, 0);
                }
                else
                {
                    listView1.Items.Add(item.RoomName + "-" + item.ID, 1);
                }
            }
        }

        private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("calc.exe");
        }

        private void 开桌ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            this.Hide();
            KZForm kzFrom;
            if (RuningData.FormDir.ContainsKey("KZForm"))
            {
                kzFrom = (KZForm)RuningData.FormDir["KZForm"];
            }
            else
            {
                kzFrom = new KZForm();
            }
            kzFrom.Show();
        }

        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {
            //设置右击打开菜单时触发的监听事件
            if (listView1.SelectedItems.Count != 0)
            {
                RuningData.CurrRoomNmae = listView1.SelectedItems[0].SubItems[0].Text;
                //contextMenuStrip1.Items[0].Enabled = RuningData.GetRoom(Convert.ToInt32(RuningData.CurrRoomNmae.Split('-')[1])).RoomZT.Equals("待用") ? true : false;
                if (RuningData.GetRoom(Convert.ToInt32(RuningData.CurrRoomNmae.Split('-')[1])).RoomZT.Equals("待用"))
                {
                    contextMenuStrip1.Items[0].Enabled = true;
                    contextMenuStrip1.Items[1].Enabled = false;
                }
                else
                {
                    contextMenuStrip1.Items[0].Enabled = false;
                    contextMenuStrip1.Items[1].Enabled = true;
                }
            }
            else
            {
                contextMenuStrip1.Items[0].Enabled = false;
                contextMenuStrip1.Items[1].Enabled = false;
            }
        }

        private void xXXXXToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GLForm glf;
            if (RuningData.FormDir.ContainsKey("GLForm"))
            {
                glf = (GLForm)RuningData.FormDir["GLForm"];
            }
            else
            {
                glf = new GLForm();
            }
            glf.Show();
            this.Hide();
        }

        private void 点菜ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DCForm dcf;
            if (RuningData.FormDir.ContainsKey("DCForm"))
            {
                dcf = (DCForm)RuningData.FormDir["DCForm"];
            }
            else
            {
                dcf = new DCForm();
            }
            this.Hide();
            dcf.Show();
        }
    }
}
